package helipay.api.util;

import java.util.Date;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * 
 * @author kelvin.tie
 */
@Component
@Scope("singleton")
public class Constant {
	
	
	
	public static final String CREATE_BY_API="API_CREATE";
	public static final String UPDATE_BY_API="API_UPDATE";
	public static final String CREATE_BY_SCHEDULE_API="API_SCHEDULE_CREATE";
	public static final String UPDATE_BY_SCHEDULE_API="API_SCHEDULE_UPDATE";
	public static String PUSH_PROJECT_NAME="";
	public static String PUSH_PROJECT_URL="";
	public static String API_LINK_URL="";
	public static String API_LINK_MEDIA_PATH="";
	public static Integer AREA_VALIDATION_NUMBER=15000000;
	
	public static Integer REQUEST_PAIR_UP_TIME_EXPRID=86400;
	
	public static Boolean IS_SNET_PUSH=true;

	public static final String VALIDATION_EMAIL="[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+";
	
	public static String VALIDATION_MOBILE="^[1-9]{1}[0-9]{10}$";
	
	
	// type value create by Swing at 2015/06/12
	public static final String WALKING_DATA = "1";
	
	public static final String SLEEPING_DATA = "2";
	
    public static final String MEASURE_DATA = "3";
	
	public static final String TRAINING_DATA = "4"; 
	
	public static String getImageURL(Date createTime,String appUrl,String imageUrl){
		//5min 取得image serverPath ,否則 cep api path
		if(createTime==null){
			return appUrl;
		}
		if(DateUtil.getCurrentDate().compareTo(DateUtil.getAfterMin(createTime, 5))==-1){
			return appUrl;
		}else{
			return imageUrl;
		}
	}
	
	public static String getAPIUrl(String imageUrl){
		
		if(StringUtils.isBlank(imageUrl)){
			return "";
		}
		
		if(imageUrl.startsWith("http:") ||imageUrl.startsWith("https:")  ){
			return imageUrl;
		}
		
		String imagePath=API_LINK_URL;
		
		return imagePath + imageUrl;

	}

	public static String getUUID(){
		String pkId = UUID.randomUUID().toString().replace("-", "");
		return pkId;
	}

}
